package cn.xuexiyuan.kpi.controller;

import cn.xuexiyuan.kpi.entity.BillboardEntity;
import cn.xuexiyuan.kpi.entity.PageParam;
import cn.xuexiyuan.kpi.entity.ResponseEntity;
import cn.xuexiyuan.kpi.mapper.BillboardMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/billboard")
public class BillboardController {

    @Autowired
    BillboardMapper billboardMapper;


    @RequestMapping("/save")
    public ResponseEntity save(@RequestBody BillboardEntity billboard) {
        billboardMapper.insert(billboard);
        return ResponseEntity.buildSucess(billboard, "保存成功", null);
    }


    @GetMapping("/latest")
    public ResponseEntity latest() {
        return ResponseEntity.buildSucess(billboardMapper.findLatestOne(), "成功", null);
    }


    @RequestMapping("/find")
    public ResponseEntity find(@RequestBody PageParam<BillboardEntity> param){
        List<BillboardEntity> data = billboardMapper.find(param);
        int count = billboardMapper.count(param);
        return ResponseEntity.buildSucess(data, count);
    }


    @RequestMapping("/delete")
    public ResponseEntity delete(@RequestBody BillboardEntity param){
        billboardMapper.delete(param);
        return ResponseEntity.buildSucess(null, "删除成功", null);
    }

}
